#include"SuperOF.h"
using namespace std;
string FN;
int nhw;//1.优先时间短|2.优先时间长|3.随机
bool gxh;
bool wt;//超时写入
void bs()
{
	system("cls");
	system("color 97");
	cout<<"程序遇到了错误。"<<endl;
	cout<<"请重试并不要输入错误的数据。"<<endl;
	return;
}
void set_info()
{
	color("*","*",2,0);
	cout<<"欢迎使用作业大师！本项目已在https://gitee.com/if-OF/Homework_master开放源代码。"<<endl;
	cout<<"由于您是首次使用，我们需要您设置一些初始信息。"<<endl;
	line();
	cout<<"请选择您需要在相同重要程度下优先开始的作业："<<endl;
	cout<<"1.我不在乎，随机开始."<<endl;
	cout<<"2.我想先开始需要时间最短的."<<endl;
	cout<<"3.我想先开始需要时间最长的."<<endl;
	switch(getch()-'0')
	{
		case 1:{
			nhw=1;
			break;
		}
		case 2:{
			nhw=2;
			break;
		}
		case 3:{
			nhw=3;
			break;
		}
		default:{
			bs();
			break;
		}
	}
	line();
	cout<<"您是否需要程序在开始时提示使用个性化界面："<<endl;
	cout<<"1.我不需要."<<endl;
	cout<<"2.我需要."<<endl;
	gxh=getch()-'1';
	line();
	cout<<"您是否需要程序在作业设定时间结束时将一条“作业xxxx的完成时间已经结束，但是当前的进度仅为xx%”的信息写入作业记录："<<endl;
	cout<<"1.我不需要."<<endl;
	cout<<"2.我需要."<<endl;
	wt=getch()-'1';
	line();
	cout<<"设置已完成，接下来程序将自动关闭，您可以在程序关闭后再次打开开始您的使用。"<<endl;
	system("mkdir C:\\database\\hwmaster");
	freopen("C:\\database\\hwmaster\\data.dll","w",stdout);
	cout<<nhw<<endl<<gxh<<endl<<wt<<endl;
}
bool first_open()
{
	fstream _file;
	_file.open("C:/database/hwmaster/data.dll",ios::in);
    if(!_file)
    {
    	set_info();
    	return 1;
	}
	return 0;
}
void msg(string message,int level)
{
	FILE *fp = fopen(FN.c_str(),"a+");
	if(fp==0)
	{
		printf("无法打开作业日志文件\n");
		return;
	}
	fseek(fp,0,SEEK_END);
	string otp="";
	int level_1=level;
	while(level--)	otp+="#";
	if(level!=0)	otp+=" "; 
	level_1==1?otp+=message:otp+="- "+message;
	level==0?otp+=".\n\n":otp+="\n\n";
	if(level_1==1)	otp+="\n---\n[TOC]\n---\n\n";
	fwrite(otp.c_str(),strlen(otp.c_str()),1,fp);
	fclose(fp);
}
struct Homework{
	string name,subject;
	int importance;
	int begin_time;
	int end_time;
	int spend_time=0;
	int setting_time;
	int col=1;
	bool del=0;
	bool pause=0;
	int finish/*100%*/;
	bool cue=0,cue2=0,cue3=0;
	void cout_hw()
	{
		int ip_color[]={1,2,5,9,7,13};
		string ip_text[]={"长作业","不紧急","普通","优先完成","加急","急需提交"};
		color("*","*",ip_color[importance],0);
		if(pause)
		{
			color("*","*",12,0);
			cout<<"[已暂停]\t";
			color("*","*",1,0);
		}
		if(del)
		{
			color("*","*",1,0);
			cout<<"[删除]"<<subject<<" - "<<name;
			return;
		}
		else
			cout<<"["<<ip_text[importance]<<"]";
		color("*","*",1,0);
		if(subject=="语文")
			color("green-l","black",-1,-1);
		if(subject=="数学")
			color("yellow-l","black",-1,-1);
		if(subject=="英语")
			color("red-l","black",-1,-1);
		if(subject=="物理")
			color("cyan-d","black",-1,-1);
		if(subject=="地理")
			color("green-d","black",-1,-1);
		if(subject=="生物")
			color("yellow-d","black",-1,-1);
		cout<<subject;
		color("*","*",1,0);
		cout<<" - ";
		color("*","*",col,0);
		cout<<name;
		return;
	}
	string HW_S_md()
	{
		string ans="";
		string ip_text[]={"长作业","不紧急","普通","优先完成","加急","急需提交"};
		string col_s[]={"#000000","#ffffff","#00dd00","#006600","#000066","#0000dd","#660000","#dd0000",\
		"#666600","#dddd00","#006666","#00dddd","#660066","#dd00dd","#666666"};
		if(pause)
		{
			ans+="<font color=\""+col_s[12]+"\">**[已暂停]**</font>";
		}
		if(del)
		{
			ans+="<font color=\""+col_s[14]+"\">";
			ans+="*[删除]";
			cout<<subject;
			ans+=subject.c_str();
			ans+=" - ";
			ans+=name.c_str();
			ans+="*</font>";
			return ans;
		}
		else
		{
			int ip_color[]={1,2,5,9,7,13};
			ans+="<font color=\""+col_s[ip_color[importance]]+"\">";
			ans+="["+ip_text[importance]+"]"+"</font>";
			if(subject=="语文")
				ans+="<font color=\""+col_s[2]+"\">"+subject+"</font> - ";
			else if(subject=="数学")
				ans+="<font color=\""+col_s[9]+"\">"+subject+"</font> - ";
			else if(subject=="英语")
				ans+="<font color=\""+col_s[7]+"\">"+subject+"</font> - ";
			else if(subject=="物理")
				ans+="<font color=\""+col_s[10]+"\">"+subject+"</font> - ";
			else if(subject=="地理")
				ans+="<font color=\""+col_s[3]+"\">"+subject+"</font> - ";
			else if(subject=="生物")
				ans+="<font color=\""+col_s[8]+"\">"+subject+"</font> - ";
			else ans+=subject+" - ";
			if(col!=1 && col!=0)
				ans+="<font color=\""+col_s[col]+"\">"+name+"</font>";
			else
				ans+=name;
		}
		return ans;
	}
};
string weekday(int dow)
{
	switch(dow)
	{
		case 1:{
			return "一";
			break;
		}
		case 2:{
			return "二";
			break;
		}
		case 3:{
			return "三";
			break;
		}
		case 4:{
			return "四";
			break;
		}
		case 5:{
			return "五";
			break;
		}
		case 6:{
			return "六";
			break;
		}
		case 0:{
			return "日";
			break;
		}
	}
}
int main()
{
	if(first_open())
		return 0;
	freopen("C:/database/hwmaster/data.dll","r",stdin);
	cin>>nhw>>gxh>>wt;
	freopen("CON","r",stdin);
	int HW_num;
	color("cyan-l", "black", -1, -1);
	cout<<"作业大师 v1.10.53"<<endl;
	cout<<"if-OF(c)2020-2021 版权所有"<<endl;
	color("white", "black",-1,-1);
	line();
	color("green-l", "black",-1,-1);
	SYSTEMTIME sys_t;
	GetLocalTime(&sys_t);
	cout<<sys_t.wYear<<"/"<<sys_t.wMonth<<"/"<<sys_t.wDay<<" 星期"<<weekday(sys_t.wDayOfWeek)<<endl;
	string date=int_to_string(sys_t.wYear)+"."+int_to_string(sys_t.wMonth)+"."+int_to_string(sys_t.wDay);
	FN=date+"作业日志.md";
	fstream _file;
	_file.open(FN.c_str(),ios::in);
	FILE *fp = fopen(FN.c_str(),"a+");
	if(fp==0)
	{
		printf("无法打开作业日志文件\n");
		return 0;
	}
	fseek(fp,0,SEEK_END);
	bool first=0;
    if(!_file)
    {
    	msg(date+" 的作业日志",1);
	}
	string message="## - 于"+date+" "+int_to_string(sys_t.wHour)+":"+int_to_string\
	(sys_t.wMinute)+":"+int_to_string(sys_t.wSecond)+"打开了作业大师.\n\n";
	fwrite(message.c_str(),strlen(message.c_str()),1,fp);
	fclose(fp);
	color("yellow-l", "black",-1,-1);
	cout<<"请输入作业数量："<<endl;
	cin>>HW_num;
	Homework hw[1024];
	if(HW_num<0 || HW_num>1024)
	{
		bs();
	}
	color("white", "black",-1,-1);
	line();
	color("cyan-d", "black",-1,-1);
	char get_ch='0';
	if(gxh)
	{
		cout<<"是否使用个性化界面？"<<endl;
		cout<<"\t1.是\t2.否"<<endl;
		get_ch=getch();
	}
	bool col=false;
	if(get_ch=='1')
		col=true;
	cout<<"请以此输入作业的名称，学科，优先度及预估时间。"<<endl;
	cout<<"请使用以下的形式输入："<<endl;
	cout<<"名称 学科 优先度(0-5) 预估时间(min) "<<endl;
	if(col)
	{
		cout<<"请注意，您选择了个性化界面，需要在作业名称后填写颜色代码(0-13)"<<endl;
	}
	color("white", "black",-1,-1);
	line();
	color("red-d", "black",-1,-1);
	for(int i=0;i<HW_num;i++)
	{
		cout<<i+1<<".";
		cin>>hw[i].name>>hw[i].subject>>hw[i].importance>>hw[i].setting_time;
		if(col)
			cin>>hw[i].col;
		msg("添加了作业:"+hw[i].HW_S_md(),0);
	}
	HW_num--;
	color("white", "black",-1,-1);
	line();
	color("cyan-l", "black",-1,-1);
	cout<<"作业大师-控制台端 开始运行。"<<endl;
	cout<<"按 'O' 进行操作"<<endl;
	color("white", "black",-1,-1);
	Sleep(2500);
	line();
	color("cyan-l", "black",-1,-1);
	int now_do=-1;
	system("cls");
	while(1)
	{
		Sleep(25);
		GetLocalTime(&sys_t);
		cls();
		color("cyan-l", "black",-1,-1);
		cout<<"作业大师-控制台"<<endl<<"按 'O' 进行操作"<<endl;
		color("white", "black",-1,-1);
		line();
		color("cyan-l", "black",-1,-1);
		cout<<sys_t.wYear<<"/"<<sys_t.wMonth<<"/"<<sys_t.wDay<<" "<<sys_t.wHour\
		<<":"<<sys_t.wMinute<<":"<<sys_t.wSecond<<"."<<sys_t.wMilliseconds<<"\t\t\n";
		cout<<"当前任务："<<endl;
		if(now_do==-1)
			cout<<"无";
		else
			hw[now_do].cout_hw();
		cout<<"             "<<endl;
		if(now_do==-1)
		{
			color("cyan-d", "white",-1,-1);
			progress_bar(12,1,1);
		}
		else
		{
			if(time(NULL)-hw[now_do].begin_time>=hw[now_do].setting_time*60)
			{
				color("red-l", "white",-1,-1);
				cout<<"时间:";
				progress_bar(12,1,1);
			}
			else
			{
				time(NULL)-hw[now_do].begin_time<=hw[now_do].setting_time*60*0.75?color("green-d", "white",-1,-1):color("yellow-d", "white",-1,-1);
				cout<<"时间:";
				progress_bar(12,time(NULL)-hw[now_do].begin_time+hw[now_do].spend_time,hw[now_do].setting_time*60);
			}
		}
		cout<<endl;
		if(now_do!=-1)
		{
			cout<<"\t"<<(time(NULL)-hw[now_do].begin_time+hw[now_do].spend_time)/60<<"/"<<hw[now_do].setting_time<<"\t";
			printf("%0.2f\%\t\n",((time(NULL)-hw[now_do].begin_time+hw[now_do].spend_time)*1.0/(hw[now_do].setting_time*60))*100);
			color("blue-d", "white",-1,-1);
			cout<<"进度:";
			progress_bar(12,hw[now_do].finish,100);
			cout<<endl;
			printf("\t%d.0\%\t\n",hw[now_do].finish);
			if(time(NULL)-hw[now_do].begin_time+hw[now_do].spend_time>=hw[now_do].setting_time*60)
			{
				color("red-l","black",-1,-1);
				cout<<"时间到了哦！加油！"<<endl;
				if(!hw[now_do].cue && wt)
				{
					msg("作业"+hw[now_do].HW_S_md()+"的完成时间已经在"+int_to_string(sys_t.wHour)+":"+int_to_string(sys_t.wMinute)\
					+"结束，但是此时的完成进度仅为"+int_to_string(hw[now_do].finish),0);
					hw[now_do].cue=1;
				}
			}
			else if(time(NULL)-hw[now_do].begin_time+hw[now_do].spend_time>=hw[now_do].setting_time*60*0.75)
			{
				color("yellow-l","black",-1,-1);
				cout<<"时间过了75%哦！加油！"<<endl;;
				if(!hw[now_do].cue2 && wt)
				{
					msg("作业"+hw[now_do].HW_S_md()+"的完成时间已经在"+int_to_string(sys_t.wHour)+":"+int_to_string(sys_t.wMinute)\
					+"过去了75%，此时的完成进度为"+int_to_string(hw[now_do].finish),0);
					hw[now_do].cue2=1;
				}
			}
			else if(hw[now_do].setting_time>0 && (time(NULL)-hw[now_do].begin_time+hw[now_do].spend_time)>600)
			{
				if(100*(time(NULL)-hw[now_do].begin_time+hw[now_do].spend_time)/(hw[now_do].setting_time*60)>=hw[now_do].finish)
				{
					color("blue-d","black",-1,-1);
					cout<<"进度有些慢了哦！加油！"<<endl;
				}
			}
		}
		if(_kbhit())
		{
			if(_getch()=='o' || _getch()=='O')
			{
				color("cyan-l", "black",-1,-1);
				cout<<"请选择操作："<<endl;
				cout<<"0.取消操作"<<endl;
				cout<<"1.开始新的一项作业"<<endl;
				cout<<"2.更新当前作业进度"<<endl;
				cout<<"3.添加新的作业"<<endl;
				cout<<"4.删除已设置的作业"<<endl;
				cout<<"5.查看作业列表"<<endl;
				cout<<"6.输出总结并关闭"<<endl;
				string in;
				int opt=0;
				Sleep(150);
				cin>>in;
				for(int i=0;i<in.length();i++)
				{
					if(in[i]<'0' || in[i]>'9')
					{
						bs();
						Sleep(5000);
						break;
					}
					opt*=10;
					opt+=in[i]-'0';
				}
				switch(opt)
				{
					case 0:{
						break;
					}
					case 1:{
						if(now_do!=-1)
						{
							cout<<"当前有正在进行的作业：";
							hw[now_do].cout_hw();
							cout<<"，进行新的作业会暂停当前作业。"<<endl;
							cout<<"是否继续？\n1.继续\n2.取消\n";
							char aa=getch();
							if(aa!='1')
								break;
						}
						cout<<"请选择操作：\n1.智能推荐\n2.手动选择\n";
						switch(getch()-'0')
						{
							case 1:{
								int chh=-1;
								switch(nhw)
								{
									case 2:{
										int mint=99999999;
										for(int j=5;j>=0;j--)
										{
											for(int i=0;i<=HW_num;i++)
											{
												if(hw[i].del || hw[i].importance!=j)	continue;
												if(hw[i].setting_time<mint)
													chh=i,mint=hw[i].setting_time;
											}
											if(chh!=-1)
												break;
										}
										break;
									}
									case 3:{
										int maxt=-99999999;
										for(int j=5;j>=0;j--)
										{
											for(int i=0;i<=HW_num;i++)
											{
												if(hw[i].del || hw[i].importance!=j)	continue;
												if(hw[i].setting_time>maxt)
													chh=i,maxt=hw[i].setting_time;
											}
											if(chh!=-1)
												break;
										}
										break;
									}
									case 1:{
										int ft=2048;
										srand(time(0));
										for(int i=3;i>=0;i--)
										{
											do{
												chh=rand()%(HW_num+1);
												ft--;
												if(ft<=0)
												{
													chh=-1;
												}
											}while((hw[chh].del || hw[chh].importance!=i) && ft>0);
											if(chh!=-1)
												break;
										}
										break;
									}
								}
								if(chh==-1)
								{
									cout<<"暂无推荐的作业."<<endl;
									Sleep(3000);
									break;
								}
								else
								{
									cout<<"系统推荐您接下来完成";
									hw[chh].cout_hw();
									cout<<"，是否接受？\n1.接受\n2.不接受\n";
									if(getch()=='1')
									{
										if(now_do!=-1)
										{
											msg("于"+int_to_string(sys_t.wHour)+":"+int_to_string(sys_t.wMinute)+\
											"暂停了作业:"+hw[now_do].HW_S_md()+",当前完成了"+int_to_string(hw[now_do].finish)+"%",0);
											hw[now_do].pause=1;
											hw[now_do].spend_time+=time(NULL)-hw[now_do].begin_time;
										}
										now_do=chh;
										hw[now_do].pause=0;
										hw[now_do].begin_time=time(NULL);
										color("green-l","black",-1,-1);
										GetLocalTime(&sys_t);
										msg("于"+int_to_string(sys_t.wHour)+":"+int_to_string(sys_t.wMinute)+\
										"开始了系统推荐的新作业:"+hw[now_do].HW_S_md()+",时间限度为"+int_to_string(hw[now_do].setting_time)+"分钟",0);
										cout<<"设置成功。"<<endl;
										break;
									}
									else
									{
										break;
									}
								}
								break;
							}
							case 2:{
								cout<<"请选择添加的作业编号："<<endl;
								color("white", "black",-1,-1);
								cout<<"0.取消"<<endl;
								for(int i=0;i<=HW_num;i++)
								{
									if(hw[i].del)	continue;
									color("white", "black",-1,-1);
									cout<<i+1<<".";
									hw[i].cout_hw();
									cout<<endl;
								}
								int to_do_hw;
								cin>>to_do_hw;
								if(to_do_hw==0)
									break;
								if(now_do!=-1)
								{
									msg("于"+int_to_string(sys_t.wHour)+":"+int_to_string(sys_t.wMinute)+\
									"暂停了作业:"+hw[now_do].HW_S_md()+",当前完成了"+int_to_string(hw[now_do].finish)+"%",0);
									hw[now_do].pause=1;
									hw[now_do].spend_time+=time(NULL)-hw[now_do].begin_time;
								}
								now_do=to_do_hw-1;
								hw[now_do].pause=0;
								hw[now_do].begin_time=time(NULL);
								color("green-l","black",-1,-1);
								GetLocalTime(&sys_t);
								msg("于"+int_to_string(sys_t.wHour)+":"+int_to_string(sys_t.wMinute)+\
								"开始了新作业:"+hw[now_do].HW_S_md()+",时间限度为"+int_to_string(hw[now_do].setting_time)+"分钟",0);
								cout<<"设置成功。"<<endl;
								break;
							}
							default:{
								bs();
								Sleep(5000);
								break;
							}
						}
						break; 
					}
					case 2:{
						if(now_do==-1)
						{
							cout<<"请先开始一项作业"<<endl;
							Sleep(3000);
							break;
						}
						cout<<"请选择调节项目："<<endl;
						cout<<"1.最大时间限度\n2.当前作业进度\n";
						char get_ch1=getch();
						switch(get_ch1)
						{
							case '1':{
								cout<<"请设置调整后的最大时间限度"<<endl;
								string cin_t;
								int nt=0;
								cin>>cin_t;
								for(int i=0;i<cin_t.length();i++)
								{
									if(cin_t[i]<'0' || cin_t[i]>'9')
									{
										bs();
										Sleep(5000);
										break;
									}
									nt*=10;
									nt+=cin_t[i]-'0';
								}
								msg("于"+int_to_string(sys_t.wHour)+":"+int_to_string(sys_t.wMinute)+"将作业:"+hw[now_do].HW_S_md()\
								+"的时间限度由"+int_to_string(hw[now_do].setting_time)+"分钟调整为"+int_to_string(nt)+"分钟",0);
								hw[now_do].setting_time=nt;
								break;
							}
							case '2':{
								cout<<"请设定当前的作业进度"<<endl;
								string cin_t;
								int nt=0;
								cin>>cin_t;
								for(int i=0;i<cin_t.length();i++)
								{
									if(cin_t[i]<'0' || cin_t[i]>'9')
									{
										bs();
										Sleep(5000);
										break;
									}
									nt*=10;
									nt+=cin_t[i]-'0';
								}
								if(nt<0 || nt>100)
								{
									bs();
										Sleep(5000);
										break;
								}
								if(nt==100)
								{
									cout<<"已完成当前作业\n";
									hw[now_do].finish=100;
									hw[now_do].end_time=time(NULL);
									hw[now_do].spend_time+=hw[now_do].end_time-hw[now_do].begin_time;
									msg("于"+int_to_string(sys_t.wHour)+":"+int_to_string(sys_t.wMinute)+"完成作业:"+hw[now_do].HW_S_md()+"，总耗时"+int_to_string((hw[now_do]\
									.spend_time)/60)+"分钟，占预期时间的"+int_to_string((hw[now_do].spend_time*100)/(hw[now_do].setting_time*60)),0);
									hw[now_do].del=1;
									now_do=-1;
									Sleep(3000);
								}
								else
								{
									msg("于"+int_to_string(sys_t.wHour)+":"+int_to_string(sys_t.wMinute)+"将作业:"+hw[now_do].HW_S_md()\
									+"的完成情况由"+int_to_string(hw[now_do].finish)+"%调整为"+int_to_string(nt)+"%",0);
								} 
								hw[now_do].finish=nt;
								break;
							}
							default:
							{
								bs();
								Sleep(5000);
							}
						}
						break;
					}
					case 3:{
						cout<<"请以此输入作业的名称，学科，优先度及预估时间。"<<endl;
						cout<<"请使用以下的形式输入："<<endl;
						cout<<"名称 学科 优先度(0-5) 预估时间(min) "<<endl;
						if(col)
						{
							cout<<"请注意，您选择了个性化界面，需要在作业名称后填写颜色代码(1-13)，填0默认白色"<<endl; 
						}
						color("white", "black",-1,-1);
						line();
						color("red-d", "black",-1,-1);
						HW_num++;
						cin>>hw[HW_num].name>>hw[HW_num].subject>>hw[HW_num].importance>>hw[HW_num].setting_time;
						if(col)
							cin>>hw[HW_num].col;
						color("green-l","black",-1,-1);
						msg("添加了作业:"+hw[HW_num].HW_S_md(),0);
						cout<<"添加成功"<<endl;
						break;
					}
					case 4:{
						cout<<"删除作业后作业将不再显示，但可在此恢复。"<<endl;
						cout<<"请选择操作："<<endl;
						cout<<"1.删除作业\n2.恢复删除的作业\n";
						switch(getch())
						{
							case '1':{
								cout<<"请选择要删除的作业:"<<endl;
								for(int i=0;i<=HW_num;i++)
								{
									if(hw[i].del)	continue;
									color("white", "black",-1,-1);
									cout<<i+1<<".";
									hw[i].cout_hw();
									cout<<endl;
								}
								string cin_t;
								int nt=0;
								cin>>cin_t;
								for(int i=0;i<cin_t.length();i++)
								{
									if(cin_t[i]<'0' || cin_t[i]>'9')
									{
										bs();
										Sleep(5000);
										break;
									}
									nt*=10;
									nt+=cin_t[i]-'0';
								}
								if(nt<0 || nt>HW_num+1)
								{
									bs();
									cout<<nt<<" "<<HW_num;
									Sleep(5000); 
									break;
								}
								nt-=1;
								msg("于"+int_to_string(sys_t.wHour)+":"+int_to_string(sys_t.wMinute)+"删除了作业:"+hw[nt].HW_S_md(),0);
								hw[nt].del=1;
								cout<<"已删除"<<endl;
								Sleep(1000);
								break;
							}
							case '2':{
								cout<<"请选择要恢复的作业:"<<endl;
								for(int i=0;i<=HW_num;i++)
								{
									color("white", "black",-1,-1);
									cout<<i+1<<".";
									hw[i].cout_hw();
									cout<<endl;
								}
								string cin_t;
								int nt=0;
								cin>>cin_t;
								for(int i=0;i<cin_t.length();i++)
								{
									if(cin_t[i]<'0' || cin_t[i]>'9')
									{
										bs();
										Sleep(5000);
										break;
									}
									nt*=10;
									nt+=cin_t[i]-'0';
								}
								if(nt<0 || nt>HW_num+1)
								{
									bs();
									Sleep(5000);
									break;
								}
								cout<<"已恢复"<<endl;
								nt-=1;
								msg("于"+int_to_string(sys_t.wHour)+":"+int_to_string(sys_t.wMinute)+\
								"恢复了被删除的作业:"+hw[nt].HW_S_md(),0);
								hw[nt].del=0;
								Sleep(1000);
								break;
							}
							default:
							{
								bs();
								Sleep(5000);
							}
						}
						break;
					}
					case 5:{
						for(int i=0;i<=HW_num;i++)
						{
							color("white", "black",-1,-1);
							cout<<i+1<<".";
							hw[i].cout_hw();
							cout<<endl;
						}
						cout<<"按任意键关闭."<<endl;
						getch();
						break;
					}
					case 6:{
						msg("于"+int_to_string(sys_t.wHour)+":"+int_to_string(sys_t.wMinute)+"关闭了程序，以下是本次运行报告：",3);
						FILE *fp = fopen(FN.c_str(),"a+");
						if(fp==0)
						{
							printf("无法打开作业日志文件\n");
							return 0;
						}
						fseek(fp,0,SEEK_END);
						string otp="|作业|状态|完成进度|总耗时|设置时间|耗时占比|\n";
						fwrite(otp.c_str(),strlen(otp.c_str()),1,fp);
						otp="|----|----|----|----|----|\n";
						fwrite(otp.c_str(),strlen(otp.c_str()),1,fp);
						for(int i=0;i<=HW_num;i++)
						{
							bool boo=hw[i].del;
							hw[i].del=0;
							otp="|"+hw[i].HW_S_md();
							otp+="|";
							boo?otp+="已删除|":otp+="正常|";
							otp+=int_to_string(hw[i].finish)+"%|";
							otp+=int_to_string(hw[i].spend_time/60)+":"+int_to_string(hw[i].spend_time%60)+"min|";
							otp+=int_to_string(hw[i].setting_time/60)+":"+int_to_string(hw[i].setting_time%60)+"min|";
							hw[i].setting_time==0?otp+="inf%|\n":otp+=int_to_string(hw[i].spend_time/hw[i].setting_time)+"%|\n";
							fwrite(otp.c_str(),strlen(otp.c_str()),1,fp);
						}
						fclose(fp);
						return 0;
						break;
					}
					default:{
						bs();
						Sleep(5000);
						break;
					}
				}
				color("white", "black",-1,-1);
				line();
				color("cyan-l", "black",-1,-1);
				system("cls");
			}
		}
	}
}